import router from "./router";
import store from "./store";
const loginList = ["/login", "/404"];
router.beforeEach((to, from, next) => {
  if (store.state.login.token) {
    if (to.path.toLowerCase() === "/login") {
      next("/layout");
    } else {
      next();
      if (!store.state.login.infoList.id) {
        store.dispatch("login/getinfo");
      }
    }
  } else {
    if (loginList.includes(to.path.toLowerCase())) {
      next();
    } else {
      next("/login");
    }
  }
});
